package com.atguigu.day11.function;

import com.atguigu.bean.Acc;
import org.apache.flink.table.functions.AggregateFunction;

public class MyUDAF extends AggregateFunction<Integer, Acc> {

    @Override
    public Integer getValue(Acc accumulator) {
        return accumulator.getAcc();
    }

    @Override
    public Acc createAccumulator() {
        Acc acc = new Acc();
        acc.setAcc(Integer.MIN_VALUE);
        return acc;
    }

    public void accumulate(Acc acc, Integer iValue) {
        System.out.println("accumulate>>>>>");
        acc.setAcc(Math.max(acc.getAcc(), iValue));
    }

    public void resetAccumulator(Acc acc) {
        System.out.println("resetAccumulator");
        acc.setAcc(Integer.MIN_VALUE);
    }
}
